//
//  ZZSignInController.m
//  QQplayground
//
//  Created by zhangxy on 2018/7/19.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZSignInController.h"

#import "ZTextView.h"
#import "ChooseTypeController.h"
#import "ChooseLabelController.h"
#import "NavTypeEntity.h"

#import "MyButton.h"
#import "XHImageViewer.h"

#import "RITLPhotos.h"

#import "UIView+Border.h"
#import "CalendarView.h"

@interface ZZSignInController (){
    
}


@property(nonatomic,strong) UIScrollView *mainScroll;
@property(nonatomic,strong) CalendarView *calendarView;
@property(nonatomic,strong) UILabel *labTips;
@property(nonatomic,strong) UIImageView *imgProgress;


@end

@implementation ZZSignInController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"每日签到";
    [self setNavigationBar];
    [self.view setBackgroundColor:UIColorFromRGB(BgSystemColor)];
    
    
    [self createSignView];
}

-(void)createSignView{
    _mainScroll = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    [_mainScroll setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:_mainScroll];
    
    _mainScroll.showsHorizontalScrollIndicator = NO;
    _mainScroll.showsVerticalScrollIndicator = NO;
    _mainScroll.alwaysBounceHorizontal = NO;
    _mainScroll.alwaysBounceVertical = YES;
    _mainScroll.pagingEnabled = NO;
    //    _mainScroll.bounces = NO;
    _mainScroll.scrollEnabled = YES;
    
    [self createTopItems];
}

-(void)tagClick:(UIButton *)btn{
    // 100-103,
    if(btn.tag == 105){
        //签到
    }
}



-(void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)createTopItems{
    UIImageView  *topBgView = [self createImageView];
    [topBgView setFrame:CGRectMake(0, 0, ScreenWidth, 219)];
    [topBgView setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
    [_mainScroll addSubview:topBgView];
    
    
    CGFloat x = 20;
    CGFloat space = (ScreenWidth - 40 - 44*4)/3;
    NSArray *days = @[@"3天",@"7天",@"15天",@"30天"];
    NSArray *arrColor = @[UIColorFromRGB(0x87E0E0),UIColorFromRGB(0x7EC1FF),UIColorFromRGB(0x9C89FC),UIColorFromRGB(0xFF70A6)];
    CGFloat y = 30;
    for (int i=0; i < 4; i ++ ) {
        UIButton *btn = [self createButton];
        [btn setFrame:CGRectMake(x+44*i+space*i, y, 44, 44)];
        [btn setBackgroundColor:arrColor[i]];
        btn.layer.cornerRadius = 22.0f;
        btn.layer.masksToBounds = YES;
        [btn setTitle:@"领取" forState:0];
        [btn addTarget:self action:@selector(tagClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 100+i;
        [btn.titleLabel setFont:FontThirteen];
        
        UILabel *lab = [self createLabel];
        [lab setTextAlignment:NSTextAlignmentCenter];
        [lab setText:days[i]];
        [lab setFont:FontThirteen];
        [lab setTextColor:UIColorFromRGB(Text6Color)];
        [lab setFrame:CGRectMake(x+44*i+space*i, y+44, 44, 21)];
        
        
        [_mainScroll addSubview:btn];
        [_mainScroll addSubview:lab];
    }
    
    UIImageView  *lineView = [self createImageView];
    [lineView setFrame:CGRectMake(20, 107, ScreenWidth-40, 2)];
    [lineView setBackgroundColor:UIColorFromRGB(BgSystemColor)];
    [_mainScroll addSubview:lineView];
    
    
    _imgProgress = [self createImageView];
    [_imgProgress setFrame:CGRectMake(20, 107, (ScreenWidth-40)*0.5, 2)];
    [_imgProgress setBackgroundColor:UIColorFromRGB(BgTitleColor)];
    [_mainScroll addSubview:_imgProgress];
    
    
    _labTips = [self createLabel];
    [_labTips setTextAlignment:NSTextAlignmentCenter];
    [_labTips setText:[NSString stringWithFormat:@"累计签到%d天  累计签到%d天",10,10]];
    [_labTips setFont:FontThirteen];
    [_labTips setTextColor:UIColorFromRGB(Text6Color)];
    [_labTips setFrame:CGRectMake(20, 120, ScreenWidth - 40, 21)];
    
    [_mainScroll addSubview:_labTips];
    
    
    UIButton *btnSign = [self createButton];
    [btnSign setFrame:CGRectMake(20, 155, ScreenWidth - 40, 44)];
    [btnSign setBackgroundColor:UIColorFromRGB(BgTitleColor)];
    btnSign.layer.cornerRadius = 10.0f;
    btnSign.layer.masksToBounds = YES;
    [btnSign setTitle:@"签到" forState:0];
    btnSign.tag = 105;
    [btnSign addTarget:self action:@selector(tagClick:) forControlEvents:UIControlEventTouchUpInside];
    [btnSign.titleLabel setFont:FontThirteen];
    [_mainScroll addSubview:btnSign];
    
    
    _calendarView = [[CalendarView alloc] initWithFrame:CGRectMake(10, 229, ScreenWidth - 20, 300)];
    _calendarView.layer.cornerRadius = 10.0f;
    _calendarView.layer.masksToBounds = YES;
    [_mainScroll addSubview:_calendarView];
    
    NSString *text = @"活动须知\n\n1、每位用户每天只能签到一次。 \n\n2、用户连续签到才可领取礼包。\n\n3、满足以下任一条件的：签到断开、连续30天签到礼包已领取，系统则会重新计算连续签到。 \n\n4、每月每位用户最多使用5张补签卡，补签卡会在商城出售。 \n\n5、本活动最终解释权归Q友乐园所有。 若遇到问题请到此 反馈 给我们。";
    UILabel *lab = [self createLabel];
    [lab setTextAlignment:NSTextAlignmentLeft];
    [lab setText:text];
    [lab setFont:FontThirteen];
    [lab setTextColor:UIColorFromRGB(Text6Color)];
    [lab setFrame:CGRectMake(20, 539, ScreenWidth - 40, 200)];
    [_mainScroll addSubview:lab];
    
    
    [_mainScroll setContentSize:CGSizeMake(ScreenWidth, CGRectGetMaxY(lab.frame))];
    
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch {
    
    if ([touch.view isKindOfClass:[UIScrollView class]]) {
        
        return YES;
        
    }
    
    return NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/**
 计算Label高度
 
 @param label 要计算的label，设置了值
 @param width label的最大宽度
 */
- (CGSize )autoWidthOfLabel:(UILabel *)label with:(CGFloat )height{
    //Calculate the expected size based on the font and linebreak mode of your label
    // FLT_MAX here simply means no constraint in height
    CGSize maximumLabelSize = CGSizeMake(FLT_MAX, height);
    
    CGSize expectedLabelSize = [label sizeThatFits:maximumLabelSize];
    
    //adjust the label the the new height.
    CGRect newFrame = label.frame;
    newFrame.size.width = expectedLabelSize.width;
    label.frame = newFrame;
    [label updateConstraintsIfNeeded];
    
    return expectedLabelSize;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
